package o;

import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Build.VERSION;
import android.text.format.Formatter;
import android.util.DisplayMetrics;
import android.util.Log;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;

public final class ux {
    private final Context ˊ;
    private final int ˋ;
    private final int ˎ;
    private final int ˏ;

    interface d {
        int ˊ();

        int ˎ();
    }

    static final class c implements d {
        private final DisplayMetrics ˊ;

        c(DisplayMetrics displayMetrics) {
            this.ˊ = displayMetrics;
        }

        public int ˊ() {
            return this.ˊ.widthPixels;
        }

        public int ˎ() {
            return this.ˊ.heightPixels;
        }
    }

    public static final class e {
        static final int ˊ = (VERSION.SDK_INT < 26 ? 4 : 1);
        float ʻ = 0.4f;
        float ʼ = 0.33f;
        float ʽ = ((float) ˊ);
        final Context ˋ;
        float ˎ = 2.0f;
        ActivityManager ˏ;
        d ॱ;
        int ॱॱ = 4194304;

        public e(Context context) {
            this.ˋ = context;
            this.ˏ = (ActivityManager) context.getSystemService("activity");
            this.ॱ = new c(context.getResources().getDisplayMetrics());
            if (VERSION.SDK_INT >= 26 && ux.ˏ(this.ˏ)) {
                this.ʽ = 0.0f;
            }
        }

        public ux ˊ() {
            return new ux(this);
        }
    }

    ux(e eVar) {
        int i;
        this.ˊ = eVar.ˋ;
        if (ˏ(eVar.ˏ)) {
            i = eVar.ॱॱ / 2;
        } else {
            i = eVar.ॱॱ;
        }
        this.ˎ = i;
        int ˋ = ˋ(eVar.ˏ, eVar.ʻ, eVar.ʼ);
        i = (eVar.ॱ.ˊ() * eVar.ॱ.ˎ()) * 4;
        int round = Math.round(((float) i) * eVar.ʽ);
        i = Math.round(((float) i) * eVar.ˎ);
        int i2 = ˋ - this.ˎ;
        if (i + round <= i2) {
            this.ˏ = i;
            this.ˋ = round;
        } else {
            float f = ((float) i2) / (eVar.ʽ + eVar.ˎ);
            this.ˏ = Math.round(eVar.ˎ * f);
            this.ˋ = Math.round(f * eVar.ʽ);
        }
        if (Log.isLoggable("MemorySizeCalculator", 3)) {
            Log.d("MemorySizeCalculator", "Calculation complete, Calculated memory cache size: " + ˊ(this.ˏ) + ", pool size: " + ˊ(this.ˋ) + ", byte array size: " + ˊ(this.ˎ) + ", memory class limited? " + (i + round > ˋ) + ", max size: " + ˊ(ˋ) + ", memoryClass: " + eVar.ˏ.getMemoryClass() + ", isLowMemoryDevice: " + ˏ(eVar.ˏ));
        }
    }

    public int ˏ() {
        return this.ˏ;
    }

    public int ˎ() {
        return this.ˋ;
    }

    public int ˋ() {
        return this.ˎ;
    }

    private static int ˋ(ActivityManager activityManager, float f, float f2) {
        float memoryClass = (float) ((activityManager.getMemoryClass() * WXMediaMessage.DESCRIPTION_LENGTH_LIMIT) * WXMediaMessage.DESCRIPTION_LENGTH_LIMIT);
        if (!ˏ(activityManager)) {
            f2 = f;
        }
        return Math.round(memoryClass * f2);
    }

    private String ˊ(int i) {
        return Formatter.formatFileSize(this.ˊ, (long) i);
    }

    @TargetApi(19)
    static boolean ˏ(ActivityManager activityManager) {
        if (VERSION.SDK_INT >= 19) {
            return activityManager.isLowRamDevice();
        }
        return true;
    }
}
